package com.atguigu.webapp.controller.appointment;



import com.atguigu.common.constant.LoginUserContext;
import com.atguigu.common.result.Result;
import com.atguigu.model.pojo.ViewAppointment;
import com.atguigu.webapp.service.ViewAppointmentService;
import com.atguigu.webapp.vo.appointment.AppointmentDetailVo;
import com.atguigu.webapp.vo.appointment.AppointmentItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "看房预约信息")
@RestController
@RequestMapping("/app/appointment")
public class ViewAppointmentController {

    @Autowired
    private ViewAppointmentService viewAppointmentService;

    @Operation(summary = "保存或更新看房预约")
    @Parameters({
            @Parameter(name = "viewAppointment",description = "看房预约对象",in = ParameterIn.QUERY)
    })
    @PostMapping("saveOrUpdate")
    public Result<Boolean> saveOrUpdate(@RequestBody ViewAppointment viewAppointment) {

        //将获取到的用户id存入看房预约对象
        viewAppointment.setUserId(LoginUserContext.getLoginUser().getUserId());
        boolean b = viewAppointmentService.saveOrUpdate(viewAppointment);
        return Result.ok(b);
    }

    @Operation(summary = "查询个人预约看房列表")
    @GetMapping("listItem")
    public Result<List<AppointmentItemVo>> listViewAppointmentItem() {
        List<AppointmentItemVo> voList = viewAppointmentService.listAppointmentItemByUserId(LoginUserContext.getLoginUser().getUserId());
        return Result.ok(voList);
    }


    @GetMapping("getDetailById")
    @Parameters({
            @Parameter(name = "id",description = "预约详情id",in = ParameterIn.QUERY)
    })
    @Operation(summary = "根据ID查询预约详情信息")
    public Result<AppointmentDetailVo> getAppointmentDetailById(Long id) {
        AppointmentDetailVo detailVo = viewAppointmentService.getAppointmentDetailById(id);
        return Result.ok(detailVo);
    }

}

